<template>
  <div class="search">
    <f-form ref="form" :action="api.custom" :form-key="this.formItem.customId">
      <f-form-item label="区域" type='select' :data='api.custom.provider' name="areaName" :value="formItem.areaName" :required="true"/>
      <f-form-item label="客户名称" name="customName" :value="formItem.customName" :required="true"/>
      <f-form-item label="联系人" name="linkMan" :value="formItem.linkMan"/>
      <f-form-item label="联系电话" name="telephone" :value="formItem.telephone"/>
      <f-form-item label="按流向结算" type="switch" name="settleType" :value="formItem.settleType"/>
      <f-form-item label="资信天数" type="number"  name="reputation" dataType="number" :precision="0" :value="formItem.reputation"/>
      <f-form-item label="资信额度" type="number" data-type="number"  name="reputationAmount" :value="formItem.reputationAmount"/>
      <f-form-item label="备注" name="remark" :value="formItem.remark"/>
      <div v-if="isAdd">
      <a-divider orientation="left">收货地址</a-divider>
      <f-form-item label="收货地址" name="address1" :value="formItem.address1"/>
      <f-form-item label="收货人" name="userName1" :value="formItem.userName1"/>
      <f-form-item label="联系电话" name="telephone1" :value="formItem.telephone1"/>

      <a-divider orientation="left">发票收件地址</a-divider>
      <f-form-item label="收件地址" name="address2" :value="formItem.address2"/>
      <f-form-item label="收件人" name="userName2" :value="formItem.userName2"/>
      <f-form-item label="联系电话" name="telephone2" :value="formItem.telephone2"/>
      </div>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'customForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          customId: '',
          customName: '',
          linkMan: '',
          telephone: '',
          address: '',
          ownerState:0,
          customState: '',
          allowJs: '',
          remark: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.customId) {
          let params = {
            customId: data.customId
          }
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({}, callback)
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
